

<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>aiy.voice.audio &mdash; AIY Projects 2018-11-16 documentation</title>
  

  
  
  
  

  
  <script type="text/javascript" src="_static/js/modernizr.min.js"></script>
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="./" src="_static/documentation_options.js"></script>
        <script src="_static/jquery.js"></script>
        <script src="_static/underscore.js"></script>
        <script src="_static/doctools.js"></script>
        <script src="_static/language_data.js"></script>
    
    <script type="text/javascript" src="_static/js/theme.js"></script>

    

  
  <link rel="stylesheet" href="_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="_static/custom.css" type="text/css" />
    <link rel="index" title="Index" href="genindex.html" />
    <link rel="search" title="Search" href="search.html" />
    <link rel="next" title="aiy.voice.tts" href="aiy.voice.tts.html" />
    <link rel="prev" title="aiy.cloudspeech" href="aiy.cloudspeech.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="index.html" class="icon icon-home"> AIY Projects
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">Common APIs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="aiy.board.html">aiy.board</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.leds.html">aiy.leds</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.pins.html">aiy.pins</a></li>
</ul>
<p class="caption"><span class="caption-text">Vision Kit APIs</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="vision.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.toneplayer.html">aiy.toneplayer</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.trackplayer.html">aiy.trackplayer</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.annotator.html">aiy.vision.annotator</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.inference.html">aiy.vision.inference</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.vision.models.html">aiy.vision.models</a></li>
</ul>
<p class="caption"><span class="caption-text">Voice Kit APIs</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="voice.html">Overview</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.assistant.html">aiy.assistant</a></li>
<li class="toctree-l1"><a class="reference internal" href="aiy.cloudspeech.html">aiy.cloudspeech</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">aiy.voice.audio</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#recording">Recording</a></li>
<li class="toctree-l2"><a class="reference internal" href="#playback">Playback</a></li>
<li class="toctree-l2"><a class="reference internal" href="#audio-format">Audio format</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="aiy.voice.tts.html">aiy.voice.tts</a></li>
</ul>
<p class="caption"><span class="caption-text">Other docs</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian">Source code (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/CHANGES.md">Change log (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/HACKING.md">Software setup (GitHub)</a></li>
<li class="toctree-l1"><a class="reference external" href="https://github.com/google/aiyprojects-raspbian/blob/aiyprojects/CONTRIBUTING.md">Contribution guide (GitHub)</a></li>
</ul>

            
          
        </div>
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="index.html">AIY Projects</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="index.html">Docs</a> &raquo;</li>
        
      <li>aiy.voice.audio</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
            
            <a href="_sources/aiy.voice.audio.rst.txt" rel="nofollow"> View page source</a>
          
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <div class="section" id="aiy-voice-audio">
<h1>aiy.voice.audio<a class="headerlink" href="#aiy-voice-audio" title="Permalink to this headline">¶</a></h1>
<p>APIs to record and play audio files.</p>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>These APIs are designed for the Voice Kit, but have no dependency on the Voice
HAT/Bonnet specifically. However, many of the APIs require some type of sound card
attached to the Raspberry Pi that can be detected by the ALSA subsystem.</p>
</div>
<span class="target" id="module-aiy.voice.audio"></span><div class="section" id="recording">
<h2>Recording<a class="headerlink" href="#recording" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="aiy.voice.audio.arecord">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">arecord</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filetype='raw'</em>, <em class="sig-param">filename=None</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.arecord" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an <code class="docutils literal notranslate"><span class="pre">arecord</span></code> command-line command.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filetype</strong> – The type of file. Must be either ‘wav’, ‘raw’, ‘voc’, or ‘au’.</p></li>
<li><p><strong>filename</strong> – The audio file to play.</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.record_file">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">record_file</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filename</em>, <em class="sig-param">filetype</em>, <em class="sig-param">wait</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.record_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Records an audio file (blocking). The length of the recording is determined by a
blocking <code class="docutils literal notranslate"><span class="pre">wait</span></code> function that you provide. When your <code class="docutils literal notranslate"><span class="pre">wait</span></code> function finishes,
so does this function and the recording.</p>
<p>For an example, see <a class="reference external" href="https://github.com/google/aiyprojects-raspbian/tree/aiyprojects/src/examples/voice/voice_recorder.py">src/examples/voice/voice_recorder.py</a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filename</strong> – The file where the recording should be saved.</p></li>
<li><p><strong>filetype</strong> – The type of file. Must be either ‘wav’, ‘raw’, ‘voc’, or ‘au’.</p></li>
<li><p><strong>wait</strong> – A blocking function that determines the length of the recording (and thus the
length of time that this function is blocking).</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.record_file_async">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">record_file_async</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filename</em>, <em class="sig-param">filetype</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.record_file_async" title="Permalink to this definition">¶</a></dt>
<dd><p>Records an audio file, asynchronously. To stop the recording, terminate the returned
<a class="reference external" href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code></a> object.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filename</strong> – The file where the recording should be saved.</p></li>
<li><p><strong>filetype</strong> – The type of file. Must be either ‘wav’, ‘raw’, ‘voc’, or ‘au’.</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The <a class="reference external" href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code></a> object for the subprocess in which audio is recording.</p>
</dd>
</dl>
</dd></dl>

<dl class="class">
<dt id="aiy.voice.audio.Recorder">
<em class="property">class </em><code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">Recorder</code><a class="headerlink" href="#aiy.voice.audio.Recorder" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference external" href="https://docs.python.org/3/library/functions.html#object" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">object</span></code></a></p>
<dl class="method">
<dt id="aiy.voice.audio.Recorder.done">
<code class="sig-name descname">done</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.Recorder.done" title="Permalink to this definition">¶</a></dt>
<dd><p>Stops the recording that started via <a class="reference internal" href="#aiy.voice.audio.Recorder.record" title="aiy.voice.audio.Recorder.record"><code class="xref py py-meth docutils literal notranslate"><span class="pre">record()</span></code></a>.</p>
</dd></dl>

<dl class="method">
<dt id="aiy.voice.audio.Recorder.join">
<code class="sig-name descname">join</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.Recorder.join" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="aiy.voice.audio.Recorder.record">
<code class="sig-name descname">record</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">chunk_duration_sec</em>, <em class="sig-param">device='default'</em>, <em class="sig-param">num_chunks=None</em>, <em class="sig-param">on_start=None</em>, <em class="sig-param">on_stop=None</em>, <em class="sig-param">filename=None</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.Recorder.record" title="Permalink to this definition">¶</a></dt>
<dd><p>Records audio with the ALSA soundcard driver, via <code class="docutils literal notranslate"><span class="pre">arecord</span></code>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>chunk_duration_sec</strong> – The duration of each audio chunk, in seconds (may be float).</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
<li><p><strong>num_chunks</strong> – The number of chunks to record. Leave as <code class="docutils literal notranslate"><span class="pre">None</span></code> to instead record
indefinitely, until you call <a class="reference internal" href="#aiy.voice.audio.Recorder.done" title="aiy.voice.audio.Recorder.done"><code class="xref py py-meth docutils literal notranslate"><span class="pre">done()</span></code></a>.</p></li>
<li><p><strong>on_start</strong> – A function callback to call when recording starts.</p></li>
<li><p><strong>on_stop</strong> – A function callback to call when recording stops.</p></li>
<li><p><strong>filename</strong> – A filename to use if you want to save the recording as a WAV file.</p></li>
</ul>
</dd>
<dt class="field-even">Yields</dt>
<dd class="field-even"><p>A chunk of audio data. Each chunk size = <code class="docutils literal notranslate"><span class="pre">chunk_duraction_sec</span> <span class="pre">*</span> <span class="pre">fmt.bytes_per_second</span></code></p>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="playback">
<h2>Playback<a class="headerlink" href="#playback" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="aiy.voice.audio.aplay">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">aplay</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filetype='raw'</em>, <em class="sig-param">filename=None</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.aplay" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns an <code class="docutils literal notranslate"><span class="pre">aplay</span></code> command-line command.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filetype</strong> – The type of file. Must be either ‘wav’, ‘raw’, ‘voc’, or ‘au’.</p></li>
<li><p><strong>filename</strong> – The audio file to play.</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.play_raw">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">play_raw</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filename_or_data</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.play_raw" title="Permalink to this definition">¶</a></dt>
<dd><p>Plays raw audio data (blocking).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filename_or_data</strong> – The file or bytes to play.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.play_raw_async">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">play_raw_async</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filename_or_data</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.play_raw_async" title="Permalink to this definition">¶</a></dt>
<dd><p>Plays raw audio data asynchronously.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filename_or_data</strong> – The file or bytes to play.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The <a class="reference external" href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code></a> object for the subprocess in which audio is playing.</p>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.play_wav">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">play_wav</code><span class="sig-paren">(</span><em class="sig-param">filename_or_data</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.play_wav" title="Permalink to this definition">¶</a></dt>
<dd><p>Plays a WAV file or data (blocking).</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>filename_or_data</strong> – The WAV file or bytes to play.</p>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.play_wav_async">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">play_wav_async</code><span class="sig-paren">(</span><em class="sig-param">filename_or_data</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.play_wav_async" title="Permalink to this definition">¶</a></dt>
<dd><p>Plays a WAV file or data asynchronously.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>filename_or_data</strong> – The WAV file or bytes to play.</p>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>The <a class="reference external" href="https://docs.python.org/3/library/subprocess.html#subprocess.Popen" title="(in Python v3.8)"><code class="xref py py-class docutils literal notranslate"><span class="pre">Popen</span></code></a> object for the subprocess in which audio is playing.</p>
</dd>
</dl>
</dd></dl>

<dl class="class">
<dt id="aiy.voice.audio.BytesPlayer">
<em class="property">class </em><code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">BytesPlayer</code><a class="headerlink" href="#aiy.voice.audio.BytesPlayer" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">aiy.voice.audio.Player</span></code></p>
<p>Plays audio from a given byte data source.</p>
<dl class="method">
<dt id="aiy.voice.audio.BytesPlayer.join">
<code class="sig-name descname">join</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.BytesPlayer.join" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="aiy.voice.audio.BytesPlayer.play">
<code class="sig-name descname">play</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.BytesPlayer.play" title="Permalink to this definition">¶</a></dt>
<dd><dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
<dt class="field-even">Returns</dt>
<dd class="field-even"><p>A closure with an inner function <code class="docutils literal notranslate"><span class="pre">push()</span></code> that accepts the byte data.</p>
</dd>
</dl>
</dd></dl>

</dd></dl>

<dl class="class">
<dt id="aiy.voice.audio.FilePlayer">
<em class="property">class </em><code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">FilePlayer</code><a class="headerlink" href="#aiy.voice.audio.FilePlayer" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">aiy.voice.audio.Player</span></code></p>
<p>Plays audio from a file.</p>
<dl class="method">
<dt id="aiy.voice.audio.FilePlayer.join">
<code class="sig-name descname">join</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.FilePlayer.join" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="aiy.voice.audio.FilePlayer.play_raw">
<code class="sig-name descname">play_raw</code><span class="sig-paren">(</span><em class="sig-param">fmt</em>, <em class="sig-param">filename</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.FilePlayer.play_raw" title="Permalink to this definition">¶</a></dt>
<dd><p>Plays a raw audio file.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>fmt</strong> – The audio format; an instance of <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p></li>
<li><p><strong>filename</strong> – The audio file to play.</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="method">
<dt id="aiy.voice.audio.FilePlayer.play_wav">
<code class="sig-name descname">play_wav</code><span class="sig-paren">(</span><em class="sig-param">filename</em>, <em class="sig-param">device='default'</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.FilePlayer.play_wav" title="Permalink to this definition">¶</a></dt>
<dd><p>Plays a WAV file.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>filename</strong> – The WAV file to play.</p></li>
<li><p><strong>device</strong> – The PCM device name. Leave as <code class="docutils literal notranslate"><span class="pre">default</span></code> to use the default ALSA soundcard.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="audio-format">
<h2>Audio format<a class="headerlink" href="#audio-format" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="aiy.voice.audio.wave_set_format">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">wave_set_format</code><span class="sig-paren">(</span><em class="sig-param">wav_file</em>, <em class="sig-param">fmt</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.wave_set_format" title="Permalink to this definition">¶</a></dt>
<dd><p>Sets the format for the given WAV file, using the given <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a>.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><ul class="simple">
<li><p><strong>wav_file</strong> – A <code class="xref py py-class docutils literal notranslate"><span class="pre">wave.Wave_write</span></code> object.</p></li>
<li><p><strong>fmt</strong> – A <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a> object.</p></li>
</ul>
</dd>
</dl>
</dd></dl>

<dl class="function">
<dt id="aiy.voice.audio.wave_get_format">
<code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">wave_get_format</code><span class="sig-paren">(</span><em class="sig-param">wav_file</em><span class="sig-paren">)</span><a class="headerlink" href="#aiy.voice.audio.wave_get_format" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">AudioFormat</span></code></a> corresponding to the WAV file provided.</p>
<dl class="field-list simple">
<dt class="field-odd">Parameters</dt>
<dd class="field-odd"><p><strong>wav_file</strong> – A <code class="xref py py-class docutils literal notranslate"><span class="pre">wave.Wave_read</span></code> object.</p>
</dd>
</dl>
</dd></dl>

<dl class="class">
<dt id="aiy.voice.audio.AudioFormat">
<em class="property">class </em><code class="sig-prename descclassname">aiy.voice.audio.</code><code class="sig-name descname">AudioFormat</code><a class="headerlink" href="#aiy.voice.audio.AudioFormat" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a class="reference internal" href="#aiy.voice.audio.AudioFormat" title="aiy.voice.audio.AudioFormat"><code class="xref py py-class docutils literal notranslate"><span class="pre">aiy.voice.audio.AudioFormat</span></code></a></p>
<dl class="attribute">
<dt id="aiy.voice.audio.AudioFormat.CD">
<code class="sig-name descname">CD</code><em class="property"> = AudioFormat(sample_rate_hz=44100, num_channels=2, bytes_per_sample=2)</em><a class="headerlink" href="#aiy.voice.audio.AudioFormat.CD" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<dl class="method">
<dt id="aiy.voice.audio.AudioFormat.bytes_per_second">
<em class="property">property </em><code class="sig-name descname">bytes_per_second</code><a class="headerlink" href="#aiy.voice.audio.AudioFormat.bytes_per_second" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

</dd></dl>

</div>
</div>


           </div>
           
          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="aiy.voice.tts.html" class="btn btn-neutral float-right" title="aiy.voice.tts" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="aiy.cloudspeech.html" class="btn btn-neutral float-left" title="aiy.cloudspeech" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
        &copy; Copyright 2018, Google LLC

    </p>
  </div>
  Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>

        </div>
      </div>

    </section>

  </div>
  


  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>